package com.wc.alorithm_blue_bridge._思维.Q1368;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congge
 * @Date 2023/11/1 10:38
 * https://www.lanqiao.cn/problems/1368/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=8
 */
public class Answer {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = (int) sc.nextLong();
        int m = (int) sc.nextLong();
        long[] a = new long[n + 1];
        long[] b = new long[n + 3];
        long[] c = new long[n + 3];
        for (int i = 1; i <= n; i++) {
            b[i] = a[i] - a[i - 1];
        }
//        System.out.println(Arrays.toString(a));
        int l, r;
        long s, e;
        for (int i = 0; i < m; i++) {
            l = (int) sc.nextLong();
            r = (int) sc.nextLong();
            s = sc.nextLong();
            e = sc.nextLong();
            long d = (e - s) / (r - l);
            c[l] += s;
            c[l + 1] += (-s + d);
            c[r + 1] += (-e - d);
            c[r + 2] += e;
        }

        long sum = 0;
        for (int i = 1; i <= n; i++) {
            b[i] = b[i-1] + c[i];
            a[i] = a[i - 1] + b[i];
            sum += a[i];
        }
//        System.out.println(Arrays.toString(a));
        System.out.println(sum);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public long nextLong() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (long) in.nval;
        }
    }
}
